const path = require("path");

const pkg = require("./package.json");

const version = pkg.version;
const name = pkg.name;
const config =
  process.env.APP_ENV === "WORKER"
    ? {
        entry: "./src/worker/sql.worker.ts",
        output: {
          path: path.resolve(__dirname, "worker"),
          filename: "sql.worker.js",
          libraryTarget: "umd",
        },
      }
    : {
        entry: "./src/main/index.ts",
        output: {
          path: path.resolve(__dirname, "dist"),
          filename: `${name}-${version}.min.js`,
          libraryTarget: "umd",
          library: "monacoSqlAutocomplete",
          libraryExport: "default",
        },
      };

module.exports = {
  stats: {
    children: true,
  },
  mode: "production",
  ...config,
  module: {
    rules: [
      {
        test: /\.ts$/,
        use: ["babel-loader", "ts-loader"],
        exclude: [path.resolve(__dirname, "node_modules")],
      },
      {
        test: /\.worker\.ts$/,
        use: [
          {
            loader: "worker-loader",
            options: {
              inline: "no-fallback",
              filename: "[name].js",
            },
          },
          "ts-loader",
        ],
      },
    ],
  },
  resolve: {
    extensions: [".ts", ".js"],
  },

  // devtool: "inline-source-map"
};
